using System.Linq;
using SubsidiosBussinessLogic.DataAccess.Interfaces;
using SubsidiosBussinessLogic.Models;

namespace SubsidiosBussinessLogic.DataAccess.SqlServerRepository
{
    public class SubsidioRepository : SolicitudRepository, ISubsidioRepository
    {
        public SubsidioRepository(IDataContextFactory dataContextFactory) : base(dataContextFactory)
        {
        }

        public IQueryable<Subsidio> GetSubsidios()
        {
            return DataContextFactory.Context.GetTable<Subsidio>();
        }

        public Subsidio CreateSubsidio()
        {
            Solicitud solicitud = CreateSolicitud();
            Subsidio subsidio = new Subsidio {Solicitud = solicitud};
            DataContextFactory.Context.GetTable<Subsidio>().InsertOnSubmit(subsidio);
            return subsidio;


        }

        public void DeleteSubsidio(Subsidio subsidio)
        {
            DeleteSolicitud(subsidio.Solicitud);
            SaveAll();
        }

        public void SaveSubsidio()
        {
            SaveSolicitud();
            SaveAll();
        }
    }
}